package com.zznode.redsun.commons.dto;

import org.springframework.util.StringUtils;

import com.zznode.csp.domain.commons.util.MapCreaterBuilder;

public class ProductQuery extends QueryParameter {
	private String model;
	private Long providerId;

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public Long getProviderId() {
		return providerId;
	}

	public void setProviderId(Long providerId) {
		this.providerId = providerId;
	}

	@Override
	public String buildSql(String querySql, MapCreaterBuilder parameters) {
		StringBuilder sqlBuilder = new StringBuilder(super.buildSql(querySql, parameters, null));
		if (null != providerId) {
			sqlBuilder.append(" and provider_id = :providerId");
			parameters.put("providerId", providerId);
		}
		if (StringUtils.hasText(model)) {
			sqlBuilder.append(" and model = :model");
			parameters.put("model", model);
		}

		return sqlBuilder.toString();
	}

}
